package com.kamistoat.netty.zerocopy_old;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 传统IO文件传输服务器端
 */
public class OldIOServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(7001);
            while(true){
                Socket socket = serverSocket.accept();
                // 从socket中获取InputStream
                DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
                try {
                    byte[] bytes = new byte[4096];
                    // 读取文件到bytes，读取后不做操作直接丢弃，复用bytes，下一次读取时直接覆盖上次读取的内容
                    while (true){
                        int read = dataInputStream.read(bytes, 0, bytes.length);
                        if(read == -1){
                            break;
                        }
                    }
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
